package com.mys2sh.dispatcher;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import jofc2.model.Chart;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;

import com.opensymphony.xwork2.ActionInvocation;

@SuppressWarnings("serial")
public class OfcResult extends StrutsResultSupport {

	private static final String ENCODING = "UTF-8";

	@Override
	protected void doExecute(String finalLocation, ActionInvocation invocation)
			throws Exception {

		Chart chart = (Chart) invocation.getStack().findValue("ofc");
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json-rpc;charset=" + ENCODING);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Pragma", "No-cache");
		String json = chart.toString();
		response.setContentLength(json.getBytes(ENCODING).length);
		PrintWriter out = response.getWriter();
		out.print(json);
		out.flush();
		out.close();

	}

}
